# https://leetcode-cn.com/problems/house-robber/
# 198. 打家劫舍

from typing import List


class Solution:
    def rob(self, nums: List[int]) -> int:
        if (len(nums) == 1):
            return nums[0]
        dp = [0] * len(nums)
        dp[0] = nums[0]
        dp[1] = max(nums[0], nums[1])
        for i in range(2, len(nums)):
            dp[i] = max(dp[i-1], dp[i-2] + nums[i])
        
        # print(dp)
        return dp[len(nums)-1]

a = Solution()
a.rob([2,1,1,2])